<<style>

</style>

<template>
    <div class="table">
        <!-- 头部菜单按钮 -->
        <div class="table-header">
             <Row>
                <Col span="24">
                    <div style="float:right;"> 
                        <Input v-model="keywords" placeholder="请输入..." style="width: 150px"></Input>
                        <Button type="ghost" icon="ios-search">搜索</Button>
                    </div>
                </Col>
            </Row>
        </div>
        <Table border :columns="columns" :data="list"></Table>
        <Page :current.sync="page" :total="total_count" :page-size="limit" @on-change="getList"  show-total show-elevator :style="{'text-align': 'center'}"></Page>
        <Modal v-model="showAudit" width="240px">
            <audit ref="auditModal" @closeAudit="closeAuditModal" :auditid="cid"></audit>
            <div slot="footer"></div>
        </Modal>
        <Modal v-model="showResponse" width="600px" title="回复用户评论">
            <response ref="responseModal" @closeResponse="closeResponseModal"></response>
            <div slot="footer"></div>
        </Modal>
    </div>
</template>

<script>
import http from '../../../libs/http';
import audit from './audit';
import response from './response';
export default {
    components: {
        audit,
        response
    },
    data () {
        return {
            showAudit: false,
            showResponse: false,
            cid: '',  //评论id
            list: [],
            limit: 15,
            page: 1,
            total_count: 0,
            keywords: '',
            columns: [
                {
                    title: 'ID',
                    key: 'id',
                    align: 'center',
                    width: '5%'
                },
                {
                    title: '相关课程',
                    key: 'course',
                    align: 'center'
                },
                {
                    title: '问题',
                    key: 'question',
                    align: 'center'
                },
                {
                    title: '回答',
                    key: 'answer',
                    align: 'center'
                },
                {
                    title: '评论',
                    key: 'content',
                    align: 'center'
                },
                {
                    title: '用户名',
                    key: 'username',
                    align: 'center',
                    
                },
                {
                    title: '状态',
                    key: 'status',
                    align: 'center',
                    width: '8%',
                    render: (h, params) => {
                        switch (params.row.status) {
                            case 0:
                                return h('Button', {
                                    style: {
                                        padding: '2px 7px',
                                        color: '#fff',
                                        backgroundColor: '#80848f',
                                        borderColor: '#80848f',
                                        cursor: 'default'
                                    }
                                }, '待审核');
                                break;
                            case 1:
                                return h('Button', {
                                    style: {
                                        padding: '2px 7px',
                                        color: '#fff',
                                        backgroundColor: '#19be6b',
                                        borderColor: '#19be6b',
                                        cursor: 'default'
                                    }
                                }, '审核通过');
                                break;
                            case 2:
                                return h('Button', {
                                    style: {
                                        padding: '2px 7px',
                                        color: '#fff',
                                        backgroundColor: '#ed3f14',
                                        borderColor: '#ed3f14',
                                        cursor: 'default'
                                    }
                                }, '审核未通过');
                                break;
                        }
                    }
                },
                {
                    title: '时间',
                    key: 'create_time',
                    align: 'center',
                    width: '10%',
                },
                {
                    title: '操作',
                    key: 'action',
                    align: 'center',
                    render: (h, params) => {
                        return h('div', [
                            h('Button',{
                                props: {
                                    type: 'primary',
                                    size: 'small',
                                
                                },
                                style: {
                                    marginRight: '10px'
                                },
                                on: {
                                    click: () => {
                                        this.audit(params.row.id);
                                    }
                                }
                            }, '审核'),
                            h('Button',{
                                props: {
                                    type: 'primary',
                                    size: 'small'
                                },
                                style: {
                                    marginRight: '10px'
                                },
                                on: {
                                    click: () => {
                                        this.response(params.row.id);
                                    }
                                }
                            }, '回复'),
                            h('Button', {
                                props: {
                                    type: 'error',
                                    size: 'small'
                                },
                                on: {
                                    click: () => {
                                        this.handleRemove(params.row.id)
                                    }
                                }
                            }, '删除')
                        ])
                    }
                }
            ]
        }
    },
    methods: {
        getList( page ) {
            this.page = page;
            var that = this;
            var url = 'admin/course/comment/index/page/' + page + '/limit/' + that.limit;
            this.apiGet(url).then((res) => {
                if (res.code != 200) {
                    this.handleError(res);
                } else {
                    that.list = res.data.list;
                    that.total_count = res.data.total_count;
                }
            })
        },
        response (id) {
            this.showResponse = true;
            this.$refs.responseModal.getQuestion(id);
        },
        handleRemove(id) {
            this.$Modal.confirm({
                    width: "200",
                    content: '确认是否删除',
                    onOk: () => {
                        this.delete(id);
                    }
                });
        },
        delete(id) {
            var url = 'admin/course/comment/delete/'; 
            this.apiDelete(url, id).then((res) => {
                if (res.code != 200) {
                    this.handleError(res);
                } else {
                    this.getList(this.page);
                    this.$Message.success(res.msg);
                }
            });
        },
        closeAuditModal() {
            this.showAudit = false;
            this.getList(this.page);
        },
        closeResponseModal() {
            this.showResponse = false;
            this.getList(this.page);
        },
        audit(id) {
            this.showAudit = true;
            this.cid = id;
        }
    },
    created () {
        this.getList(this.page);
    },
    mixins: [http]
}
</script>